<?php

class SearchController extends Crb_Controller
{
    public function preDispatch()
    {
        parent::preDispatch();
        $this->view->layout()->setLayout('admin');
    }
    
    public function indexAction()
    {
        $lucene = new Search_Index();
        $this->view->info = $lucene->getInfo();
        $this->view->Title = "Поисковая система Lucene";
    }
    
    
    public function searchAction()
    {
        $this->setNoRender();
        $lucene = new Search_Index();
        
        echo "<pre>";
        print_r($lucene->search('отдых'));
        echo "</pre>";
    }
    
    
    public function performAction()
    {
        $this->setNoRender();
        $this->disableLayout();
        $lucene = new Search_Index();
        
        $operation = $this->_getParam('operation','optimize');
        
        switch ($operation) {
            case 'optimize':
                $lucene->optimize();
            break;
            
            case 'build':
                $lucene->rebuildIndex();
            break;
            
            case 'clear':
                $lucene->clear();
                $lucene->optimize();
            break;
        }
        
        echo Zend_Json::encode(  $lucene->getInfo()  );
    }
}
